#include "MultipleTypeAirplanesLoadingClr.h"
#include "DataTransform.h"

namespace LoadingWK
{

    MultipleTypeAirplanesLoadingClr::MultipleTypeAirplanesLoadingClr()
    {
        _pLoadingByMuilKindsPlane = new gaeaway_load::LoadingByMuilKindsPlane();
    }

    MultipleTypeAirplanesLoadingClr::~MultipleTypeAirplanesLoadingClr()
    {
        if (nullptr != _pLoadingByMuilKindsPlane)
        {
            delete _pLoadingByMuilKindsPlane;
            _pLoadingByMuilKindsPlane = nullptr;
        }
    }

    bool MultipleTypeAirplanesLoadingClr::importEquipmentsList(Generic::List<LoadingWK::EquipmentClr^>^ pEquipmentList)
    {
        return _pLoadingByMuilKindsPlane->importEquipments(DataTransformCLR::transformToEquipmentsOfInput(pEquipmentList));
    }

    bool MultipleTypeAirplanesLoadingClr::importAirplaneList(Generic::List<LoadingWK::AirplaneClr^>^ pAirplaneList, Double minSpacing)
    {
        if (nullptr == pAirplaneList){   return false;}

        return _pLoadingByMuilKindsPlane->importAirplaneList(DataTransformCLR::transformToAirplaneList(pAirplaneList),minSpacing);
    }

    System::Double MultipleTypeAirplanesLoadingClr::getStepOfOffsetLoad()
    {
        return _pLoadingByMuilKindsPlane->getStepOfOffsetLoad();
    }

    void MultipleTypeAirplanesLoadingClr::setStepOfOffsetLoad(Double step)
    {
        _pLoadingByMuilKindsPlane->setStepOfOffsetLoad(step);
    }

    int MultipleTypeAirplanesLoadingClr::startLoading()
    {
        //_pLoadingByMuilKindsPlane->startLoadingWithoutLimit();
        _pLoadingByMuilKindsPlane->startLoadingFromMinAirplane();
        return _pLoadingByMuilKindsPlane->getCountOfLoadedAirplanes();
    }

    System::Collections::Generic::List<LoadingWK::LoadedAirplaneClr^>^ MultipleTypeAirplanesLoadingClr::getLoadedAirplanes()
    {
        return DataTransformCLR::transformToLoadedAirplaneClrs(_pLoadingByMuilKindsPlane->getLoadedAirplanes());
    }

    LoadingWK::LoadedEquipmentListClr^ MultipleTypeAirplanesLoadingClr::getLoadedEquipments()
    {
        LoadingWK::LoadedEquipmentListClr^ pEquipmentList = gcnew LoadingWK::LoadedEquipmentListClr();

        gaeaway_load::EquipmentsOfOutput result = _pLoadingByMuilKindsPlane->getLoadedEquipments();
        for (auto ver : result)
        {
            LoadingWK::LoadedEquipmentClr^ equipment =
                gcnew LoadingWK::LoadedEquipmentClr(ver.equipmentID, ver.airplaneKindID, ver.loadedAirplanIndex, ver.leftY);

            pEquipmentList->addEquipment(equipment);
        }
        return pEquipmentList;
    }

    System::Collections::Generic::List<LoadingWK::EquipmentClr^>^ MultipleTypeAirplanesLoadingClr::getUnloadedEquipments()
    {
        gaeaway_load::EquipmentsOfInput unloadedEquipments = _pLoadingByMuilKindsPlane->getUnloadedEquipments();
        Generic::List<LoadingWK::EquipmentClr^>^ results = gcnew Generic::List<LoadingWK::EquipmentClr ^>(0);
        for (auto equipment : unloadedEquipments)
        {
            results->Add(DataTransformCLR::transformToLoadingEquipment(equipment));
        }
        return results;
    }

}